import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class add extends StatefulWidget {
  addWidget createState() => new addWidget();
}

class addWidget extends State<add> {
  TextEditingController textEditingController = new TextEditingController();
  var name = new Set();
  List<String> all=<String>['好友1','好友2','好友3','好友4','好友5','好友6',];
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: Container(
          //margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
          //padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
          child: SizedBox(
            height: MediaQuery.of(context).size.height*1/16,
            child: TextField(
              onChanged: (text){

              },
              controller: textEditingController,
              decoration: InputDecoration(
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 2.5, color: Colors.white),
                    borderRadius: BorderRadius.all(Radius.circular(5.0)),
                  ),
                  enabledBorder: (OutlineInputBorder(
                    borderSide: BorderSide(width: 2.5, color: Colors.white),
                    borderRadius: BorderRadius.all(Radius.circular(5.0)),
                  ))),
            ),
          ),
        ),
        actions: <Widget>[
          Container(
            child: FlatButton(
              child: Text('添加'),
              onPressed: () {
                //
              },
            ),
          )
        ],
      ),
      body: Container(
        child: ListView.builder(
          itemBuilder: (BuildContext context, int position) {
            bool _ischeck = name.contains(all.elementAt(position));
            return ListTile(
              title: Text(all.elementAt(position)),
              leading: Icon(Icons.person),
              trailing: _ischeck
                  ? Icon(
                      Icons.check,
                      color: Colors.red,
                    )
                  : null,
              onTap: () {
                if (_ischeck == true) {
                  setState(() {
                    name.remove(all.elementAt(position));
                  });
                } else {
                  setState(() {
                    name.add(all.elementAt(position));
                  });
                }
              },
            );
          },
          itemCount: all.length,
        ),
      ),
    );
  }
}
